package com.my.study.hutool.core;

import cn.hutool.core.bean.BeanDesc;
import cn.hutool.core.bean.DynaBean;
import cn.hutool.core.bean.PropDesc;
import com.my.study.utils.User;

/**
 * @author: yidujun
 * @create: 2021/06/30 10:11
 */
public class TestBean {

    public static void main(String[] args) {
        testDynaBean();
    }

    private static void testDynaBean() {
        DynaBean bean = DynaBean.create(User.class);
        bean.set("age", 12);
        bean.set("userName", "ydj");

        Object getUserName = bean.invoke("getUserName");
        System.out.println(getUserName);
    }

    private static void testBeanDesc() {
        User user = new User();
        user.setAge(12);
        user.setUserName("ydj");

        BeanDesc beanDesc = new BeanDesc(user.getClass());

        PropDesc prop = beanDesc.getProp("userName");
        System.out.println(prop.getValue(user));
        Object obj = prop.getValue(user, prop.getFieldType(), false);
        System.out.println(obj);

        String simpleName = beanDesc.getSimpleName();
        System.out.println(simpleName);
    }

}
